package com.sky.controller.user;

import com.sky.dto.SetmealDTO;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName: UserSetmealController
 * Package: com.sky.controller.user
 * Description:
 *
 * @Autehor 屈子岩
 * @Create 2024/9/14 11:26
 * @Version 1.0
 */
@RestController
@RequestMapping("user/setmeal")
@Slf4j
public class UserSetmealController {

    @Autowired
    private SetmealService setmealService;

    @GetMapping("list")
    @Cacheable(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")
    public Result<List<Setmeal>> list(SetmealDTO setmealDTO){
        log.info("根据分类id查询套餐信息:{}",setmealDTO);
        List<Setmeal> setmeals = setmealService.list(setmealDTO);
        if (setmeals.size() == 0){
            return Result.error("当前分类暂无套餐");
        }
        return Result.success(setmeals);
    }
    @GetMapping("dish/{id}")
    public Result<List<DishItemVO>> getByIdWithDish(@PathVariable Long id){
        log.info("根据套餐id查询套餐信息:{}",id);
        List<DishItemVO> dishItemVO = setmealService.getByIdWithDish(id);
        return Result.success(dishItemVO);
    }
}
